/**
 * @(#)SqlMapClientFactoryBean.java 2010-3-24
 * 
 * Copyright (c) 2000-2010 by ChinanetCenter Corporation.
 *
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * ChinanetCenter Corporation ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with ChinanetCenter.
 * 
 */

package com.szf.base.dao.ibatis;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.engine.execution.SqlExecutor;
import com.ibatis.sqlmap.engine.impl.SqlMapClientImpl;
import com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate;
import com.szf.util.ReflectionUtil;

public class SqlMapClientFactoryBean extends org.springframework.orm.ibatis.SqlMapClientFactoryBean {

	private Logger logger = LoggerFactory.getLogger(SqlMapClientFactoryBean.class);

	private SqlExecutor sqlExecutor;

	public void setSqlExecutor(SqlExecutor sqlExecutor) {
		this.sqlExecutor = sqlExecutor;
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		super.afterPropertiesSet();
		SqlMapClient c = getObject();
		if (sqlExecutor != null && c instanceof SqlMapClientImpl) {
			SqlMapClientImpl client = (SqlMapClientImpl) c;
			SqlMapExecutorDelegate delegate = client.getDelegate();
			ReflectionUtil.setFieldValue(delegate, "sqlExecutor", sqlExecutor);
			logger.debug("success set ibatis SqlMapClient.sqlExecutor = {}", sqlExecutor.getClass()
					.getName());
		}
	}

}
